package cn.kai.ums.controller;

import cn.kai.ums.mapper.UmsPublicCourseTeachMapper;
import cn.kai.ums.model.UmsPublicCourseTeach;
import cn.kai.ums.service.UmsPublicCourseTeachService;
import cn.kai.ums.tools.JsonData;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/ums/v1/pubcoutea")
@Api(tags = "选修上课控制类")
public class PublicCourseTeachController {

    @Autowired
    private UmsPublicCourseTeachService umsPublicCourseTeachService;

    @Autowired
    private UmsPublicCourseTeachMapper umsPublicCourseTeachMapper;


    @ApiOperation("根据课程编号和教师编号进行的模糊查询")
    @GetMapping
    public JsonData pubTeaList(@RequestParam(defaultValue = "1",required = false) Integer pageNum
            ,@RequestParam(defaultValue = "5",required = false) Integer pageSize
            ,@RequestParam(defaultValue = "",value = "likepubtea",required = false) String likepubtea){
        Page<UmsPublicCourseTeach> umsPublicCourseTeachPage = umsPublicCourseTeachMapper.selectPage(new Page<>(pageNum,pageSize)
                , Wrappers.<UmsPublicCourseTeach>lambdaQuery()
                        .like(UmsPublicCourseTeach::getPublicCourseTeachNo,likepubtea)
                        .or()
                        .like(UmsPublicCourseTeach::getPublicCourseTeacherNo,likepubtea));
        return JsonData.buildSuccess(umsPublicCourseTeachPage);
    }


    @PostMapping
    public  JsonData savePubTea(@RequestBody UmsPublicCourseTeach umsPublicCourseTeach){
        return JsonData.buildSuccess(umsPublicCourseTeachService.save(umsPublicCourseTeach));
    }


    @PutMapping
    public JsonData updatePubTea(@RequestBody UmsPublicCourseTeach umsPublicCourseTeach){
        return JsonData.buildSuccess(umsPublicCourseTeachService.updateById(umsPublicCourseTeach));
    }

    @DeleteMapping
    public JsonData delPubTea(@RequestParam Integer ptid){
        return JsonData.buildSuccess(umsPublicCourseTeachService.removeById(ptid));
    }

    @PostMapping("/delBatchPubTea")
    public JsonData delBatchPubTea(@RequestBody List<Integer> ptids){
        return JsonData.buildSuccess(umsPublicCourseTeachService.removeByIds(ptids));
    }

}
